package juc.safefinal;

/**
 * @ClassName Bar
 * @PackageName juc.safefinal
 * @projectName myThread
 * @Description 
 * @Author games
 * @Date 2025/8/29 上午9:40
 * @Version 1.0
 */
public final class Bar {
    private final Foo foo;

    public Bar(Foo foo) {
        this.foo = foo;
    }

    public Foo getFoo() {
        return foo;
    }

    public static void main(String[] args) {
        Foo2 foo1 = Foo2.create(25, "Alice");
        Foo2 foo2 = Foo2.create(25, "Alice");

        System.out.println("foo1 == foo2: " + (foo1 == foo2)); // 输出: false
        System.out.println("foo1.equals(foo2): " + foo1.equals(foo2)); // 需要重写 equals 方法

        Foo foo = Foo.create(0, "abc");
        Bar bar = new Bar(foo);
        System.out.println("Age: " + bar.getFoo().getAge());
        System.out.println("Name: " + bar.getFoo().getName());
    }
}